﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import flash.utils.*;
    import Classes.*;
    import Classes.util.*;
    import validation.*;
    import Mechanics.Transactions.*;

    public class DooberMechanic implements IDooberMechanic, IValidationMechanic {

        protected var m_owner:MechanicMapResource;
        protected var m_config:MechanicConfigData;
        protected var m_validator:GenericValidationScript;
        protected var m_sendTransactions:Boolean;

        public function DooberMechanic(){
            this.m_sendTransactions = true;
        }
        public function canGiveReward():Boolean{
            return (this.isValid());
        }
        public function isValid():Boolean{
            return (this.m_validator.validate(this.m_owner));
        }
        public function getRandomModifiersName():String{
            return (this.m_config.params["randomModifiers"]);
        }
        public function hasOverrideForGameAction(_arg1:String):Boolean{
            return (true);
        }
        public function executeOverrideForGameEvent(_arg1:String, _arg2:Array=null):MechanicActionResult{
            var _local4:Array;
            var _local3:Boolean;
            if (this.canGiveReward()){
                _local4 = new Array();
                this.m_owner.doobersArray = Global.player.processRandomModifiers(this.m_owner.getItem(), this.m_owner, true, _local4, "default", this.getRandomModifiersName());
                this.m_owner.secureRandsArray = _local4;
                this.m_owner.spawnDoobers();
                GameTransactionManager.addTransaction(new TDooberMechanicAction(this.m_owner, this.m_config.type));
                _local3 = true;
            };
            return (new MechanicActionResult(_local3, false, false));
        }
        public function initialize(_arg1:IMechanicUser, _arg2:MechanicConfigData):void{
            this.m_owner = (_arg1 as MechanicMapResource);
            this.m_config = _arg2;
            if ((_arg1 is ItemInstance)){
                this.m_validator = (_arg1 as ItemInstance).getItem().getValidation(_arg2.params["validate"]);
            };
        }
        public function getRewardInfo():Dictionary{
            return (Global.gameSettings.parseDisplayedStats(this.m_owner.getItemName(), this.m_config.rawXMLConfig.displayedStats, this.getRandomModifiersName()));
        }
        public function isVisitEnabled():Boolean{
            return (false);
        }

    }
}//package Mechanics.GameEventMechanics 
